package thread;

class SingletonLazy{
    private static Object locker = new Object();
    private static SingletonLazy instance = null;

    public static SingletonLazy getInstance(){
       // 加锁可以有提高数据的有效性，但是并不是每一个都需要加锁
        if(instance == null){
            synchronized (locker){
                // 里面有读写操作 所以要把他们当做一个整体
                if(instance == null){
                    instance = new SingletonLazy();
                }
            }
        }
        return instance;
    }

    private SingletonLazy(){}

}

public class ThreadDemo21 {
    public static void main(String[] args) {
        SingletonLazy s1 = SingletonLazy.getInstance();
        SingletonLazy s2 = SingletonLazy.getInstance();
        System.out.println(s1 == s2);
    }
}
